package br.com.biovida.persistencia.daos;

import java.lang.reflect.ParameterizedType;

import javax.ejb.Stateless;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


@Stateless
public class DAOFactory{    
    @PersistenceContext(unitName="biovidapu")    
    static EntityManager entityManagerBiovida;

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Produces
    public DAOGeneric createDAO(InjectionPoint injectionPoint) throws Exception {
        ParameterizedType type = (ParameterizedType) injectionPoint.getType();
        Class classe = (Class) type.getActualTypeArguments()[0];
        return new DAOGeneric(classe, entityManagerBiovida);    
    }

	public static EntityManager getEntityManager() {
		return entityManagerBiovida;
	}
		
}

